#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <boost/asio.hpp>

#include "mysql_management.h"

using namespace std;

int main(int argc, char* argv[]) {
  try {
    mysql_management mana;
    mana.init(10, "172.24.16.112", "chronos", "chronos", "test_yd");

    boost::asio::io_context io_context;
    auto work(boost::asio::make_work_guard(io_context));
    auto func = [&io_context, &mana](bool is_success) {
      if (!is_success) {
        return;
      }
      std::cout << "main:" << this_thread::get_id() << endl;
      // for (auto&& row : results) {
      //   ostringstream oss;
      //   for (auto&& field : row) {
      //     oss << field << ",";
      //   }
      //   cout << oss.str() << endl;
      // }
      mana.stop();
      io_context.stop();
    };
    vector<string> sqls;
    for (int i = 0; i < 1; ++i) {
      sqls.push_back(
        R"(INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES(" test ", "yd", now());)");
    }
    for (int i = 0; i < 1; ++i) {
      mana.execute(sqls, io_context, func);
    }
    io_context.run();
  } catch (std::exception& e) {
    std::cerr << "Exception: " << e.what() << "\n";
  }

  return 0;
}